package domain.message;

import junit.framework.Assert;
import junit.framework.TestCase;
import util.HierarchicalSet;
import domain.user.Member;
import domain.user.Privilege;

public class ThreadTest extends TestCase {

	Member currMember;
	Thread currForumThread;
	String currMessage;

	/**
	 * function which creates of new post and a new forumThread with a permanent member
	 * and the message currMsg and the topic subject,
	 * so we could test the other functions
	 */
	public void setUp(final String currMsg,final String subject)
	{
		this.currMember = new Member(0, "userName1","password1",new HierarchicalSet<Privilege>());
		this.currMessage = currMsg;
		this.currForumThread = new Thread(0, subject);
	}

	/**
	 * checks if the post was added to the thread
	 */
	public void testAdd()
	{
		this.setUp("msg1","exams");
		Post currPost = new Post(0, this.currMessage, this.currMember.getId(),1);
		Assert.assertEquals(false, this.currForumThread.getPosts().contains(currPost.getId()));
		Post post = new Post(2, this.currMessage, this.currMember.getId(),this.currForumThread.getId());
		this.currForumThread.addPost(post.getId());
		Assert.assertEquals(true, this.currForumThread.getPosts().contains(post.getId()));
	}

	/**
	 * checks if the post was deleted from the thread
	 */
	public void testDelete()
	{
		this.setUp("msg1","exams");
		final Post tempPost = new Post(0,"msg2", this.currMember.getId(),this.currForumThread.getId());
		this.currForumThread.addPost(tempPost.getId());
		Assert.assertEquals(true, this.currForumThread.getPosts().contains(tempPost.getId()));
		this.currForumThread.deletePost(tempPost.getId());
		Assert.assertEquals(false, this.currForumThread.getPosts().contains(tempPost.getId()));

	}

}
